<template>
	<view>
		购物车
		<view v-if="goods_lists&&goods_lists.shoppingCartItemList">
		<view v-for="item in goods_lists.shoppingCartItemList" :key="item.shoppingcartId">
			<image :src="item.skuImage" style="width:200px;height:200px;"></image>
			<view>{{item.productName}}</view>
		</view>
			<view>总价2：{{goods_lists.totalPrice/100}}</view>
		</view>
	
		 
		<button size="mini" @click="pay2()">小程序支付</button>
	 
		<button size="mini" @click="pay">支付</button>
		<button size="mini" @click="pay3()">微信支付2</button>
	</view>
</template>
<script setup>
	import {ref} from 'vue'
	import {getCart,getOpenid,getPayParams,getOrderInfo,getId} from '@/api/index.js'
	// 定义购物车数据
	const goods_lists = ref([]);
	getCart()
	.then(res=>{
		// 更新购物车数据
		goods_lists.value = res.data.goods_lists;
	})
	function pay2(){
		wx.login({
			success:async function (res){
				const {openid} =  await getOpenid({code:res.code})
				const params = await getPayParams({openid,amount:1});
				console.log(openid,params)
				wx.requestPayment({
					...params,
					signType: 'MD5',
				})
				
			}
		})
		
	};
	async function pay3(){
		
		uni.login({
			provider: 'weixin',
			onlyAuthorize:true,
			fail(err){
				console.log("fail",err)
			},
			async complete(res){
				
				const {openid} = await getId({
					action: 'loginByWeixin',
					params: {
						code: res.code,
						platform: 'mp-weixin'
					}
					}).catch(err=>{
						console.log("请求有问题",JSON.stringify(err))
					})
				console.log(openid,"openid")
				const order = await getOrderInfo({
					platform: 'app-plus',
					provider:'wxpay',	
					openid,
					totalFee: Number(2) * 100, // 转为以分
					})
				uni.requestPayment({
					provider:"wxpay",
					orderInfo:order.orderInfo,
					success(res){
						console.log(res,"res")
					}
					})
				console.log(order,"orderInfo")
			},
			success:async function(){
				console.log("成功获取",res)
				
				
			}
		})
	}
	async function pay(){
		const {orderInfo} = await getOrderInfo({
			platform: 'app-plus',
			provider:'alipay',		 
			totalFee: Number(2) * 100, // 转为以分
			})
		uni.requestPayment({
			provider:'alipay',
			orderInfo
		})
		 // uni.requestPayment({
		 // 	provider:'alipay',
			// orderInfo:'method=alipay.trade.app.pay&app_id=2015112700878442&charset=utf-8&version=1.0&sign_type=RSA2&timestamp=2023-03-15%2017%3A37%3A06&notify_url=https%3A%2F%2Fdcloud.net.cn%2Fno-where-to-request&sign=RErW8hwQIz7E8Zuc13I27BJAHwAtzRtK1%2BkywWFR1wsaWMH6XTVkYJlLaG1hztQBa%2BsvwzZGeUQSyAWsZIO7aEkZLJ1IBDY20P1VwtITnLnQ0TRoPbYfVKVWStx%2B9K%2B%2BSCbFl5UN5pqS2g1hJKpm2Wi%2FODcRgblPAwjbiCI88WZ8g9QcG0DEGpCOw%2BoS11h0mNdBeLlMyqFExLV6%2FC03MHIu57I8OzDfr94mD0XnpCxUWkudinpGoburDk1RKW30ecqoG6wCPtkYfUBblmJs1YKDAFM8RmysUMRNpZ6%2FL0kO7orR2tj6DvZ0925W54sfGl%2FX4zTU8GbjE5xy0l4JXA%3D%3D&biz_content=%7B%22out_trade_no%22%3A%221678873026535%22%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%E5%95%86%E5%9F%8E%E7%9A%84%E6%B5%8B%E8%AF%95%E8%AE%A2%E5%8D%95%E6%A0%87%E9%A2%98%22%2C%22body%22%3A%22%E6%B5%8B%E8%AF%95%E5%95%86%E5%9F%8E%E7%9A%84%E6%B5%8B%E8%AF%95%E8%AE%A2%E5%8D%95%E8%AF%A6%E6%83%85%22%2C%22total_amount%22%3A1%7D'
		 // })
	}
</script>